from multiprocessing import Process
import time


# 方法一
# # 测试函数
# def func(name):
#     print(f"{name}开始运行...")
#     time.sleep(3)
#     print(f'{name}运行结束')
#
#
# if __name__ == '__main__':
#     # 绑定的函数有参数则需要通过args来传递参数，参数为元组类型
#     p1 = Process(target=func, args=('李白',))
#     p1.start()  # 运行子进程
#
#     print("运行主进程")

# 方法二
class MyPro(Process):
    def __init__(self, name):
        super().__init__()
        self.name = name

    def run(self):
        print(f"{self.name}开始运行...")
        time.sleep(3)
        print(f'{self.name}运行结束')


if __name__ == '__main__':
    p = MyPro('里奈')
    p.start()
    print("运行主进程")
